package com.itheima.appserver.controller;

import com.itheima.appserver.service.QuestionNaireService;
import com.itheima.commons.pojo.domain.Answers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("testSoul")
public class SoulController {
    @Autowired
    QuestionNaireService questionNaireService;
    @GetMapping
    public ResponseEntity getQuestionNaireList() {
        return ResponseEntity.ok(questionNaireService.getResultList());
    }

    @GetMapping("report/{id}")
    public ResponseEntity getCheckResult(@PathVariable("id") String id) {

        return ResponseEntity.ok(questionNaireService.getResult(id));
    }

    @PostMapping
    public ResponseEntity testSoul(@RequestBody Map<String, List<Answers>> answers) {
        List<Answers> answers1 = answers.get("answers");
        return ResponseEntity.ok(questionNaireService.testSoul(answers1));
    }


}
